{extend name="property/public/insidePageBase" /}
{block name="title"}添加智能电表{/block}
{block name="body"}
<div class="layuimini-container">
    <div class="layuimini-main">
        <div class="layui-form layui-form-pane">
            <div class="layui-form-item">
                <label class="layui-form-label indispensable">设备选择</label>
                <div class="layui-input-block">
                    <select name="energy_id" lay-filter="energy_id" lay-search>
                        <option value="">-请选择-</option>
                        {foreach $meterListData as $k=>$v}
                        <option value="{$v['id']}">{$v['energy_name']}</option>
                        {/foreach}
                    </select>
                </div>
            </div>

            <div id="use_num_show"></div>
            <div class="layui-form-item">
                <label class="layui-form-label indispensable">账单编号</label>
                <div class="layui-input-block">
                    <input type="text" name="bill_number" placeholder="请输入账单编号" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">备注说明</label>
                <div class="layui-input-block">
                    <textarea placeholder="请输入备注说明" class="layui-textarea" name="remark"></textarea>
                </div>
            </div>

            <div class="layui-form-item layui-hide">
                <button class="layui-btn" lay-submit lay-filter="submitBtn" id="submitBtn">提交</button>
            </div>
        </div>
    </div>
</div>

<script id="use_num_tpl" type="text/html">
    {{# if(d.mode_type == 2) { }}
    <div class="layui-form-item">
        <div class="layui-row">
            <div class="layui-col-xs4">
                <div class="layui-form-item">
                    <label class="layui-form-label">上期底数 尖</label>
                    <div class="layui-input-block">
                        <input type="text" name="start_num_j" value="{{d.base_j}}" disabled autocomplete="off" placeholder="请输入上期底数" class="layui-input" oninput="value=value.replace(/^\D*(\d*(?:\.\d{0,2})?).*$/g, '$1')">
                    </div>
                </div>
            </div>
            <div class="layui-col-xs4">
                <div class="layui-form-item">
                    <label class="layui-form-label">结算日期</label>
                    <div class="layui-input-block">
                        <input type="text" value="{{d.base_date}}" disabled autocomplete="off"  class="layui-input">
                    </div>
                </div>
            </div>
            <div class="layui-col-xs4">
                <div class="layui-form-item">
                    <label class="layui-form-label">本期读数 尖</label>
                    <div class="layui-input-block">
                        <input type="text" name="end_num_j" value="{{d.read_j}}"  autocomplete="off" placeholder="请输入本期读数" class="layui-input" oninput="value=value.replace(/^\D*(\d*(?:\.\d{0,2})?).*$/g, '$1')">
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-row">
            <div class="layui-col-xs4">
                <div class="layui-form-item">
                    <label class="layui-form-label">上期底数 峰</label>
                    <div class="layui-input-block">
                        <input type="text" name="start_num_f" value="{{d.base_f}}" disabled autocomplete="off" placeholder="请输入上期底数" class="layui-input" oninput="value=value.replace(/^\D*(\d*(?:\.\d{0,2})?).*$/g, '$1')">
                    </div>
                </div>
            </div>
            <div class="layui-col-xs4">
                <div class="layui-form-item">
                    <label class="layui-form-label">结算日期</label>
                    <div class="layui-input-block">
                        <input type="text" value="{{d.base_date}}" disabled autocomplete="off"  class="layui-input">
                    </div>
                </div>
            </div>
            <div class="layui-col-xs4">
                <div class="layui-form-item">
                    <label class="layui-form-label">本期读数 峰</label>
                    <div class="layui-input-block">
                        <input type="text" name="end_num_f" value="{{d.read_f}}"  autocomplete="off" placeholder="请输入本期读数" class="layui-input" oninput="value=value.replace(/^\D*(\d*(?:\.\d{0,2})?).*$/g, '$1')">
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-row">
            <div class="layui-col-xs4">
                <div class="layui-form-item">
                    <label class="layui-form-label">上期底数 平</label>
                    <div class="layui-input-block">
                        <input type="text" name="start_num_p" value="{{d.base_p}}" disabled autocomplete="off" placeholder="请输入上期底数" class="layui-input" oninput="value=value.replace(/^\D*(\d*(?:\.\d{0,2})?).*$/g, '$1')">
                    </div>
                </div>
            </div>
            <div class="layui-col-xs4">
                <div class="layui-form-item">
                    <label class="layui-form-label">结算日期</label>
                    <div class="layui-input-block">
                        <input type="text" value="{{d.base_date}}" disabled autocomplete="off"  class="layui-input">
                    </div>
                </div>
            </div>
            <div class="layui-col-xs4">
                <div class="layui-form-item">
                    <label class="layui-form-label">本期读数 平</label>
                    <div class="layui-input-block">
                        <input type="text" name="end_num_p" value="{{d.read_p}}"  autocomplete="off" placeholder="请输入本期读数" class="layui-input" oninput="value=value.replace(/^\D*(\d*(?:\.\d{0,2})?).*$/g, '$1')">
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-row">
            <div class="layui-col-xs4">
                <div class="layui-form-item">
                    <label class="layui-form-label">上期底数 谷</label>
                    <div class="layui-input-block">
                        <input type="text" name="start_num_g" value="{{d.base_g}}" disabled autocomplete="off" placeholder="请输入上期底数" class="layui-input" oninput="value=value.replace(/^\D*(\d*(?:\.\d{0,2})?).*$/g, '$1')">
                    </div>
                </div>
            </div>
            <div class="layui-col-xs4">
                <div class="layui-form-item">
                    <label class="layui-form-label">结算日期</label>
                    <div class="layui-input-block">
                        <input type="text" value="{{d.base_date}}" disabled autocomplete="off"  class="layui-input">
                    </div>
                </div>
            </div>
            <div class="layui-col-xs4">
                <div class="layui-form-item">
                    <label class="layui-form-label">本期读数 谷</label>
                    <div class="layui-input-block">
                        <input type="text" name="end_num_g" value="{{d.read_g}}"  autocomplete="off" placeholder="请输入本期读数" class="layui-input" oninput="value=value.replace(/^\D*(\d*(?:\.\d{0,2})?).*$/g, '$1')">
                    </div>
                </div>
            </div>
        </div>
    </div>
    {{# } else { }}
    <div class="layui-row">
        <div class="layui-col-xs4">
            <div class="layui-form-item">
                <label class="layui-form-label">上期底数</label>
                <div class="layui-input-block">
                    <input type="text" name="start_num_z" value="{{d.base_z}}" disabled autocomplete="off" placeholder="请输入上期底数" class="layui-input" oninput="value=value.replace(/^\D*(\d*(?:\.\d{0,2})?).*$/g, '$1')">
                </div>
            </div>
        </div>
        <div class="layui-col-xs4">
            <div class="layui-form-item">
                <label class="layui-form-label">结算日期</label>
                <div class="layui-input-block">
                    <input type="text" value="{{d.base_date}}" disabled autocomplete="off"  class="layui-input">
                </div>
            </div>
        </div>
        <div class="layui-col-xs4">
            <div class="layui-form-item">
                <label class="layui-form-label">本期读数</label>
                <div class="layui-input-block">
                    <input type="text" name="end_num_z" value="{{d.read_z}}" autocomplete="off" placeholder="请输入本期读数" class="layui-input" oninput="value=value.replace(/^\D*(\d*(?:\.\d{0,2})?).*$/g, '$1')">
                </div>
            </div>
        </div>
    </div>
    {{# } }}
    <div class="layui-form-item" pane="">
        <label class="layui-form-label indispensable">结算数据</label>
        <div class="layui-input-block">
            <input type="radio" name="is_settle" lay-filter="is_settle" autocomplete="off" value="1" title="同步修改当前设备结算数据" checked>
            <input type="radio" name="is_settle" lay-filter="is_settle" autocomplete="off" value="2" title=禁止修改>
        </div>
    </div>
</script>

{/block}
{block name="js"}
{__block__}
<script>
    layui.use(['form', 'layer','laytpl'], function () {
        var form = layui.form,layer = layui.layer,  $ = layui.$,laytpl = layui.laytpl;

        form.on('select(energy_id)', function(elem) {
            loadEnertyMeterTpl()
        });

        function loadEnertyMeterTpl() {
            let energyId = $('select[name="energy_id"]').val()
            var loadIndex = layer.load(0, {time: 0});
            $.get("{:request()->url()}", {get_type: 'getEnergyMeterInfo',energy_id: energyId}, function(res) {
                layer.close(loadIndex)
                if(res.code !== 0) {
                    return layer.msg(res.msg)
                }
                var getTpl = document.getElementById('use_num_tpl').innerHTML; // 获取模板字符
                var elemView = document.getElementById('use_num_show'); // 视图对象
                // 渲染并输出结果
                laytpl(getTpl).render(res.data, function(str){
                    elemView.innerHTML = str;
                    form.render()
                });
            })
        }

    });
</script>
{/block}